package ru.reaperoq.dto

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import kotlinx.serialization.Serializable

@Serializable
data class ApiSuccess<T>(
    val success: Boolean = true,
    val data: T
)

@Serializable
data class ApiError(
    val success: Boolean = false,
    val message: String
)


suspend inline fun <reified T> ApplicationCall.respondSuccess(data: T) {
    respond(
        ApiSuccess(
            success = true,
            data = data
        )
    )
}

suspend inline fun ApplicationCall.respondError(message: String, statusCode: HttpStatusCode = HttpStatusCode.BadRequest) {
    respond(
        status = statusCode,
        ApiError(
            success = false,
            message = message
        )
    )
}